eststo clear

if("`c(os)'"=="Windows"){
	local tableSaveDir = "Tables\DiD\"
	local plotSaveDir = "Plots\"
	local pythonSaveDir = "PythonScripts\"
}
else{
	local tableSaveDir = "Tables/DiD/"
	local plotSaveDir = "Plots/"
	local pythonSaveDir = "PythonScripts/"
}

//Establish Control Variable Sets
local Spec1Controls = "ib51.stateGroup ib1995.year c.normYear#i.stateGroup c.quadYear#i.stateGroup asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage"
local Spec2Controls = "`Spec1Controls'"
local Spec3Controls = "`Spec2Controls' i.gasUseDummyExtSpec3"
local Spec4Controls = "`Spec2Controls' i.gasUseDummyExtSpec4"

//Partialled-out variables for FWL
local partialVarsSpec1 = "_cons ib51.stateGroup ib1995.year c.normYear#i.stateGroup"
local partialVarsSpec2 = "`partialVarsSpec1' i.transactionDataDummy"
local partialVarsSpec3 = "`partialVarsSpec2' i.gasUseDummyExtSpec3"
local partialVarsSpec4 = "`partialVarsSpec2' i.gasUseDummyExtSpec4"


//Establish Cluster Variable
local clusterVar = "stateGroup year"

//Absorb Vars are always time and state fixed effects
local absorbVars = "ib51.stateGroup ib1995.year"

//Establish ci level
local ciLevel = 95

//Estimate Models
//Estimate Spec1 Gas Use RF-DiD Model
// qui reghdfe loghighwaygasuse i.nosafetyind `Spec1Controls', cluster(`clusterVar') absorb(`absorbVars')
regFWL loghighwaygasuse, nosafetyind, `Spec1Controls', `absorbVars', `clusterVar', _
eststo Spec1
local df = e(N_clust)-1

//Estimate Spec2 Gas Use RF-DiD Model 
// qui reghdfe loghighwaygasuse i.nosafetyind `Spec2Controls', cluster(`clusterVar') absorb(`absorbVars')
regFWL loghighwaygasuse, nosafetyind, `Spec2Controls', `absorbVars', `clusterVar', _
eststo Spec2
local df = e(N_clust)-1

//Estimate Spec3 Gas Use RF-DiD Model
// qui reghdfe loghighwaygasuse i.nosafetyind `Spec3Controls', cluster(`clusterVar') absorb(`absorbVars')
regFWL loghighwaygasuse, nosafetyind, `Spec3Controls', `absorbVars', `clusterVar', _
eststo Spec3
local df = e(N_clust)-1

//Estimate Spec4 Gas Use RF-DiD Model
// qui reghdfe loghighwaygasuse i.nosafetyind `Spec4Controls', cluster(`clusterVar') absorb(`absorbVars')
regFWL loghighwaygasuse, nosafetyind, `Spec4Controls', `absorbVars', `clusterVar', _
eststo Spec4
local df = e(N_clust)-1


//Export Model Results to TeX Files
//Establish Format
local fmtDiD = `"cells(b(fmt(3) star) se(par fmt(3))) keep(nosafetyind_res) nocon label compress longtable mtitles("\makecell{No \\ DSCs}" "\makecell{Documented \\ DSCs}" "\makecell{Suspected \\ DSCs}" "\makecell{Potential \\ DSCs}") starlevels(* 0.1 ** 0.05 *** 0.01) addnotes("* p \textless 0.1, ** p \textless 0.05, *** p \textless 0.01" "Note: All models include state and year fixed effects as well as state-level time trends." "All models cluster standard errors  by state.")"'


//Export Table


esttab Spec1 Spec2 Spec3 Spec4 using "`tableSaveDir'GasUseRFDiD.tex", `fmtDiD' depvars title("Reduced Form Diff-in-Diff Results - Gas Use \label{tab:GasUseRFDiD}") stats(N r2, labels("Observations" "R\textsuperscript{2}")fmt(%8.0f %8.3f)) replace

